<template>
	<jk-dialog
		v-model="showDialog"
		title="详情-前纺单价"
		width="500px"
		:show-content-loading="showLoading"
		append-to-body
		:show-cancel-btn="false"
		:show-close-btn="true"
		:show-confirm-btn="false"
		@on-close="onVisibleChange(false)"
		@on-cancel="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="110px" :show-message="false">
			<el-row>
				<el-col :span="22">
					<el-form-item class="margin-bottom-10" label="工序">
						<span class="read-only-2">{{ ruleForm.processName }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="22" class="flex-start-center">
					<el-form-item class="margin-bottom-10" label="单价(元/米)">
						<div class="flex-start-center">
							<jk-number-input v-model="ruleForm.price" disabled placeholder="价格" size="small"></jk-number-input>
							<span style="white-space: nowrap;margin: 0 4px;"> / </span>
							<jk-number-input v-model="ruleForm.unit" disabled placeholder="单位" size="small"></jk-number-input>
						</div>
					</el-form-item>
				</el-col>
				<el-alert v-if="ruleForm.processCode && ruleForm.processCode.toUpperCase() === 'SM'" title="此类机台的看台人员工资固定为0，同时根据米换算公斤" class="margin-bottom-10 margin-top-10" :closable="false" show-icon size="mini" type="warning"></el-alert>
				<el-col v-if="ruleForm.processCode && ruleForm.processCode.toUpperCase() === 'SM'" :span="22" class="flex-start-center">
					<el-form-item class="margin-bottom-10" label="特殊机台">
						<div class="flex-start-center-wrap">
							<el-tag
								v-for="(machineItem, machineIndex) in ruleForm.machineItemList"
								:key="machineIndex"
								class="item-gap"
								size="large"
								style="margin-bottom: 4px;"
								type="info"
							>{{ machineItem.machineCode }}</el-tag>
						</div>
					</el-form-item>
				</el-col>
				<el-col :span="22" class="flex-start-center">
					<el-form-item class="margin-bottom-10" label="单位换算">
						<div class="flex-start-center">
							<jk-number-input v-model="ruleForm.meters" disabled placeholder="单位换算" size="small" class="item-gap"></jk-number-input>
							<span style="white-space: nowrap;font-size: 12px;color: #515a6e;">米换算公斤</span>
						</div>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-table-height';
    import { spinFrontPriceGet } from '../../../api/material/frontPriceUnitConversion';
    export default {
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataId: {
                type: [String, Number],
                default: ''
            }
        },
        mixins: [calHeight],
        data() {
            return {
                showDialog: false,
                showLoading: true,
                ruleForm: {}
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                return spinFrontPriceGet({ id: this.dataId }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.ruleForm = res.data.res;
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal && this.dataId) {
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
